package com.example.gw_back_end.controller.client;

import com.example.gw_back_end.domain.Result;
import com.example.gw_back_end.domain.entities.PostComment;
import com.example.gw_back_end.domain.entities.PostLike;
import com.example.gw_back_end.domain.entities.Warehouse;
import com.example.gw_back_end.service.PostCommentService;
import com.example.gw_back_end.service.PostLikeService;
import com.example.gw_back_end.service.PostViewService;
import com.example.gw_back_end.service.WarehouseService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("client")
public class ClientController {

    private final PostCommentService postCommentService;
    private final PostLikeService postLikeService;
    private final WarehouseService warehouseService;
    public ClientController(PostCommentService postCommentService, PostLikeService postLikeService, WarehouseService warehouseService) {
        this.postCommentService = postCommentService;
        this.postLikeService = postLikeService;
        this.warehouseService = warehouseService;
    }

    @PostMapping("add_post_comment")
    public Result addPostComment(@RequestBody PostComment postComment) {
        if (postCommentService.addPostComment(postComment)) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @DeleteMapping("delete_post_comment")
    public Result deletePostComment(@RequestBody Integer postId) {
        if (postCommentService.deletePostComment(postId)){
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @PostMapping("add_post_like")
    public Result addPostLike(@RequestBody Integer postId) {
        if (postLikeService.addPostLike(postId)) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @DeleteMapping("delete_post_like")
    public Result deletePostLike(@RequestBody Integer postId) {
        if (postLikeService.deletePostLike(postId)){
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @GetMapping("get_post_like")
    public Result getPostLike(@RequestParam Integer postId) {
        return Result.success(postLikeService.getPostLikeByPost(postId));
    }

    @GetMapping("get_warehouse")
    public Result getWarehouse () {
        return Result.success(warehouseService.getAllWarehouses());
    }
}
